#ifndef _IMATRIX_H_
#define _IMATRIX_H_

class imatrix
{
private:
	int m_iHeight, m_iWidth;
	int** p; 
	void delete_all() {
		for (int i = 0; i < m_iHeight; i++) 
				delete[] p[i];
			delete[] p;
	}
public:
	imatrix() 
    {
		m_iHeight = 1, m_iWidth = 1;
		p = new int*[m_iHeight];
		for(int i = 0; i < m_iHeight; i++)
		   p[i] = new int[m_iWidth];
        p[0][0]=1; 
    };
	imatrix(int i, int j) 
    {
		m_iHeight = i, m_iWidth = j;
		
		p = new int*[m_iHeight];
		for(i = 0; i < m_iHeight; i++)
		   p[i] = new int[m_iWidth];
    };
	imatrix(imatrix& b) {
		m_iHeight = b.m_iHeight;
		m_iWidth = b.m_iWidth;
		p = new int*[m_iHeight];
		for (int i = 0; i < m_iHeight; i++) {
			p[i] = new int[m_iWidth];
			for (int j = 0; j < m_iWidth; j++) {
				p[i][j] = b[i][j];
			}
		}
	}
	void init(int i, int j) 
    {
		delete_all();
		m_iHeight = i, m_iWidth = j;
		p = new int*[m_iHeight];
		for(i = 0; i < m_iHeight; i++)
		   p[i] = new int[m_iWidth];
    };

	~imatrix()
	{
		delete_all();
	}
	int* operator[](int i) { return p[i]; };
	void set( int i, int j, int val ) { p[i][j] = val; }
	int& get( int i, int j ) const { return p[i][j]; }
	int getRow() const { return m_iHeight; }
	int getCol() const { return m_iWidth; }
	
	void zero()
	{
		for (int i = 0; i < m_iHeight; i++) 
			for (int j = 0; j < m_iWidth; j++) 
				p[i][j] = 0;
	}
	void copy(imatrix& b)
	{
		init(b.m_iHeight, b.m_iWidth);
		for (int i = 0; i < m_iHeight; i++) 
			for (int j = 0; j < m_iWidth; j++) 
				p[i][j] = b.p[i][j];
	}
};


#endif